home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0014_Restarting Windows.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  1.7 KB  |  45 lines

  1. {
  2. There are two documented functions in the Windows API for restarting
  3. Windows: ExitWindows(), and ExitWindowsExec().  (See the Windows API help
  4. for details on both.) A common misconception is that the Program Manager DDE
  5. macro call "[Reload()]" is for restarting Windows; it is not!
  6.  
  7. The call ExitWindows( 0, EW_RESTARTWINDOWS ) is _supposed_ to shut down
  8. Windows, then bring it back up.  I've had no luck, though, from inside a
  9. Delphi app.  It just shuts down Windows and gives me a DOS prompt.
  10.  
  11. ExitWindowsExec was built so that you could shut down Windows, execute a DOS
  12. app (to replace Windows-critical DLL's, for example), and then bring Windows
  13. hack up.  I have discovered that you simply need to pass a bad executable
  14. name, and ExitWindowsExec performs exactly as ExitWindows was supposed to!
  15.  
  16. For example, the last few lines of an installation application may be:
  17.  
  18.         if (MessageDlg( 'The installation was successful!  You must now ' +
  19.                        'restart Windows.  Do this now?', mtInformation,
  20.                        [mbYes, mbNo], 0) = mrYes) then begin
  21.            ExitWindowsExec( BOGUS_EXE, Nil );
  22.         end;
  23.  
  24. where BOGUS_EXE is declared something like
  25.  
  26.         const
  27.            BOGUS_EXE = 'zyxwvuts.exe';
  28.  
  29. -JSRS
  30.  
  31. -------------------------------------------------------------------------------
  32.  
  33. This should replace (or be appended to) the tip sheet entry about restarting
  34. windows.
  35.  
  36. There is a documentation error  (probably due to the bad habits of 'C'
  37. programmers) for the ExitWindows() API call... the parameters are reversed!
  38.  
  39. This code DOES WORK... (I've tested it. ;-) )
  40.  
  41. procedure TForm1.Button1Click(Sender: TObject);
  42. begin
  43.   ExitWindows(EW_RESTARTWINDOWS,0);
  44. end;
  45.